package com.tgy.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: tgy
 * @Date: 2021/1/10 下午12:48
 * https://leetcode-cn.com/problems/summary-ranges/
 */
public class _228_汇总区间 {

    public List<String> summaryRanges(int[] nums) {

        List<String> result = new ArrayList<>();
        if (nums == null || nums.length == 0) {
            return result;
        }

        int start = 0;
        for (int i = 0; i < nums.length; i++) {

            if ((i == nums.length -1) || nums[i] + 1 != nums[i + 1]) {

                if (start == i) {
                    result.add(String.valueOf(nums[start]));
                }else {
                    result.add(nums[start] +"->"+nums[i]);
                }
                start = i+1;
            }
        }

        return result;
    }
}
